<?php
require_once __DIR__ . '/vendor/autoload.php';

use PhpAmqpLib\Connection\AMQPStreamConnection;

$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest', '/');
$channel = $connection->channel();

$channel->exchange_declare('php01', 'fanout', false, false, false);

[$queuename, ,] = $channel->queue_declare('', false, false, false, false);
$channel->queue_bind($queuename, 'php01');

echo "Waiting Receiving Message!\n";

$callback = function ($msg) {
    echo "$msg->body\n";
};

$channel->basic_consume($queuename, '', false, true, false, false, $callback);

while (count($channel->callbacks)) {
    $channel->wait();
}
